package util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;


public class DBUtil2 {
	private DBUtil2(){}
	
	private static String url;
	private static String user;
	private static String password;
	private static String className;
	
	static{
		try {
		    Properties pr=new Properties();
		    InputStream in= DBUtil2.class.getClassLoader().getResourceAsStream("db.properties");
		    pr.load(in);
		    url=pr.getProperty("url");
		    user=pr.getProperty("user");
		    password=pr.getProperty("password");
		    className=pr.getProperty("className");
		    Class.forName(className);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new RuntimeException();
		}
	}
	public static Connection getconn(){
		try {
			Connection conn=DriverManager.getConnection(url,user,password);
			return conn;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new RuntimeException();
		}
	}
	public static void close(ResultSet rs,Statement stm,Connection conn){
		if(rs!=null){
			try {
				rs.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if(stm!=null){
			try {
				stm.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if(conn!=null){
			try {
				conn.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}


